package com.googlecode.gwtbb.client.only.widget.basic;

import com.google.gwt.user.client.ui.*;

/**
 * We extend PopupPanel instead of Composite because delegating methods to a member PopupPanel
 * seems to give problems.
 * Specifically, we get java.lang.IllegalStateException: This widget's parent does not implement HasWidgets
 * in com.google.gwt.user.client.ui.Widget.removeFromParent
 * because this class does/should not implement HasWidgets and we don't want the member PopupPanel's
 * parent to become the RootPanel.
 *
 * @author Abraham Grief
 * @version $Id$
 * @since Feb 5, 2009
 */
public class Tooltip extends PopupPanel implements SourcesMouseEvents {
	private FocusPanel focusPanel;

	public Tooltip() {
		this(null);
	}

	public Tooltip(Widget widget) {
		setStylePrimaryName("gwtbb-Tooltip");
		setAnimationEnabled(false);

		focusPanel = new FocusPanel();
		super.setWidget(focusPanel);
		setWidget(widget);
	}

	@Override
	public Widget getWidget() {
		return focusPanel.getWidget();
	}

	@Override
	public void setWidget(Widget widget) {
		focusPanel.setWidget(widget);
	}

	public void addMouseListener(MouseListener listener) {
		focusPanel.addMouseListener(listener);
	}

	public void removeMouseListener(MouseListener listener) {
		focusPanel.removeMouseListener(listener);
	}
}
